package org.hawk.gwt.ppc.parser.impl.mock;

import java.util.Iterator;
import java.util.concurrent.Callable;

public class BlockExpressionMock {

	public void ifthenelse(boolean aaa, boolean bbb) {
		if (aaa) {
			print(1);
		}
		
		if (bbb) {
			print(2);
		} else if (aaa) {
			print(3);
		}
		
		if (aaa) {
			print(4);
		} else {
			print(5);
		}
		
		if (bbb) {
			print(6);
		} else if (aaa) {
			print(7);
		} else {
			print(8);
		}
		
		if (bbb) print(9);
		else if (aaa && bbb) print(10);
		else if (aaa || bbb) print(11);
		else print(12);
	}
	
	public void switchcase(int value) {
		final int THEVALUE = 1;
		
		switch(value) {
		case 3:
			break;
		case THEVALUE:
			return;
		default: {
		}
		}
		
		switch(value) {
		case 10: {break;}
		}
		switch(value) {
		default:
		}
		
		switch(value) {
		}
	}
	
	public void testWhile(Iterator<Integer> values) {
		while(values.hasNext()) {
			print(values.next());
		}
		
		while(values.hasNext()) 
			print(values.next());
	}
	
	public void testFor(int[] values) {
		for(int i = 0; i< values.length; i++) {
			values[i]++;
		}
		
		for(int i = 0; i< values.length; i++) 
			print(values[i]++);
	}
	
	public void testForeach(int[] values) {
		for (int i : values) 
			print(i);
		
		for (int i : values) {
			print(i);
		}
	}
	
	public void testDoWhile(Iterator<Integer> iterator) {
		do {
			print(iterator.next());
		} while (iterator.hasNext());
		
		do print(iterator.next());
		while (iterator.hasNext());
	}
	
	public void testTryCatchFinally() {
		try {
			print(1);
		} catch(RuntimeException ex) {
			print(2);
		} catch (InternalError err) {
			print(3);
		} finally {
			print(4);
		}
		
		try {
			print(5);
		} finally {
			print(6);
		}
		
		try {
			print(7);
			print(8);
		} catch(final java.lang.RuntimeException exception) {
			print(9);
			print(10);
		}
	}
	
	public void testInternalBlock() {
		synchronized (this) {
			print(1);
		}
		
		{
			print(2);
		}
	}
	
	public void testLabels(Iterator<Integer> iterator) {
		label0: label1: {
			label2: try {
				label3: while(iterator.hasNext()) {
					label4: synchronized(this) {
						label5: switch (iterator.next()) {
						case 0:
							break label0;
						case 1:
							break label1;
						case 2:
							break label2;
						case 3: 
							break label3;
						case 4: 
							break label4;
						case 5:
							break label5;
						}
					}
				}
			} finally {
				print(0);
			}
		}
	}
	
	public Runnable testLocalClasses() {
		final Callable<Integer> callable = new Callable<Integer>() {

			public Integer call() throws Exception {
				return 2;
			}
		};
		
		final class Local extends Object implements Runnable {

			public void run() {
				try {
					print(callable.call());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		
		return new Local();
	}
	
	private native void print(int val);
}
